//公共方法
//验证日期
function check_Date(value) {
	var a = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/
	if (!a.test(value)) {
		return false
	} else {
		return true
	}
}
//时间比较的方法，如果d2时间比d1时间大，则返回true 
function compareDate(d1, d2) {  
         return Date.parse(d1.replace(/-/g, "/")) <= Date.parse(d2.replace(/-/g, "/"))
     }
//验证数字
function check_Num(value) {
	//定义正则表达式部分
	var reg = /^\d+$/;
	if (value.constructor == String) {
		var re = value.match(reg);
		return re;
	}
	return false;
}
//验证电话
function IsTelephone(obj)// 正则判断
{ 
var pattern=/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,4}[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-10]{9}$)/; 
if(pattern.test(obj)) 
{ 
return true; 
} 
else 
{ 
return false; 
} 
} 
//验证邮箱
function IsEmail(obj)// 正则判断
{ 
var pattern=/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
if(pattern.test(obj)) 
{ 
return true; 
} 
else 
{ 
return false; 
} 
} 
//验证短日期（2007-06-05）
function strDateTime(str)
{
   var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
   if(r==null)return false; 
        var d= new Date(r[1], r[3]-1, r[4]); 
        return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}

//验证长日期(2007-06-05 10:57:10)
function strDateTime(str)
{
   var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
   var r = str.match(reg); 
   if(r==null)return false; 
   var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
   return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
} 

//验证时间(10:57:10)
function isTime(str)
{
   var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
   if (a == null) { return false;}
   if (a[1]>24 || a[3]>60 || a[4]>60)
   {
       return false
   }
    return true;
}
//把date的时间转换成客户端时区的时间
function calcTime(date,offset) {
	 try{ 
	    d = new Date(1986,02,26,date.split(":")[0],date.split(":")[1],date.split(":")[2]);
		utc = d.getTime() + ((-480) * 60000);
		nd = new Date(utc + (3600000*offset));
		//nd = new Date(parseInt(utc));
		return  FormateTime(nd.getHours(),nd.getMinutes(),nd.getSeconds());
    } finally { 
        d=null; 
        utc=null;
        nd=null;
    } 
}
//获得客户端时区
 function clientTimeZone() {

     var munites = new Date().getTimezoneOffset();

     var hour = parseInt(munites / 60);

     var munite = munites % 60;

     var prefix = "-";

     if (hour < 0 || munite < 0) {

         prefix = "+";

         hour = -hour;

         if (munite < 0) {
              munite = -munite;
         }
     }
     hour = hour + "";
     munite = munite + "";
     if (hour.length == 1) {
         hour =  hour;
     }
     if (munite.length == 1) {
         munite =  munite;
     }
     if (munite == "30") {
         munite =  "5";
     }
     if (munite == "45") {
         munite =  "75";
     }
     return prefix + hour +"."+ munite;
}
 //格式化时间，转换成00:00:00
 function FormateTime(hour,minute,second)
 {
	 try{ 
	    var h,m,s;
		 if((hour+"").length==1){
			 h="0"+hour;
			 }else{
				 h=hour;
			 }
		 if((minute+"").length==1){
			 m="0"+minute;
			 }else{
				 m=minute;
			 }
		 if((second+"").length==1){
			 s="0"+second;
			 }else{
				 s=second;
			 }
		 return h+":"+m+":"+s;
    } finally { 
        h=null; 
        m=null;
        s=null;
    } 
 }
 //返回val在规定字节长度max内的值
	function getByteVal(val, max) {
		var returnValue = '';
		var byteValLen = 0;

		for ( var i = 0; i < val.length; i++) {
			var tmp = val.charAt(i);
			if (tmp.match(/[^\x00-\xff]/ig) != null) {
				byteValLen += 2;
			} else {
				byteValLen += 1;
			}

			if (byteValLen > max) {
				break;
			}

			returnValue += tmp;
		}
		if (byteValLen > max) {
			return (returnValue.substring(0, returnValue.length - 1)) + '..';
		} else {
			return returnValue;
		}
		}
	 //返回val在规定字符长度max内的值
	function getStringVal(val, max) {
		var returnValue = '';
		var byteValLen = 0;

		for ( var i = 0; i < val.length; i++) {
			var tmp = val.charAt(i);
			if (tmp.match(/[^\x00-\xff]/ig) != null) {
				byteValLen += 2;
			} else {
				byteValLen += 2;
			}

			if (byteValLen > max) {
				break;
			}

			returnValue += tmp;
		}
		if (byteValLen > max) {
			return (returnValue.substring(0, returnValue.length - 1)) + '..';
		} else {
			return returnValue;
		}
		}